package com.muyi.biling.rest;

import com.muyi.biling.SharedPreferencesHelper;
import com.muyi.biling.bean.AppInfo;
import com.muyi.biling.util.Constants;
import rx.Scheduler;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by developer on 18-1-24.
 */

public class ApiHelper{
    private static final String APP_OS = "Android";
    private Api mApi;
    private String mDevId;
    private SharedPreferencesHelper mSharedPreferencesHelper;

    public ApiHelper(Api api, String devId, SharedPreferencesHelper sharedPreferencesHelper) {
        mApi = api;
        mDevId = devId;
        mSharedPreferencesHelper = sharedPreferencesHelper;
    }

    public void testHttp(Subscriber<ApiResult> subscriber, String ticket) {
        mApi.testHttp(ticket)
            .subscribeOn(Schedulers.io())
            .unsubscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(subscriber);
    }

    public void getAppInfo(Subscriber<AppInfo> subscriber) {
        mApi.getAppInfo(mSharedPreferencesHelper.getString(Constants.API.KEY_TICKET, ""), APP_OS, mDevId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }
}
